home *** CD-ROM | disk | FTP | other *** search
/ PsL Monthly 1993 December / PSL Monthly Shareware CD-ROM (December 1993).iso / prgmming / dos / c / stuffky.exe / STUFFKB3.ASM < prev   
Assembly Source File  |  1991-07-17  |  25KB  |  572 lines

  1. COMMENT         |
  2. STUFFKB3.ASM   By Richard Kanarek-      Compuserve ID 72371,111
  3.                                         GENIE Address: R.KANAREK
  4. Overview:
  5.         +Description of file.
  6.         +Notes on the Keyboard Buffer.
  7.         +Sample Assembly Language program which stuffs the phrase
  8.          "BUY BONDS" into your keyboard buffer. May be easily adapted
  9.          for use with Turbo C (tm- Borland Int. Inc.) by changing
  10.          a few lines (all of which are marked).
  11.         +Sample Turbo C program which calls the assembler routine
  12.          and uses it to stuff "RLK" into the buffer.
  13.  
  14. +Description of file.
  15. ---------------------
  16. This file contains information on the operation of the keyboard
  17. buffer in IBM & Zenith personal computers as well as sample procedure
  18. (in Assembler) that can be called from a Turbo C (tm) program. This
  19. file was intended to be compiled using TASM but since only TASM's
  20. MASM mode is used, compilation using Microsoft's (tm) assembler
  21. should not be difficult.
  22.  
  23. Unlike most programs, whose purpose is only to be executed, the
  24. purpose of this program is to explain the operation of the Keyboard
  25. buffer. This file is meant to help those who might wish to "stuff"
  26. or otherwise modify the keyboard buffer  on any IBM computer. Some
  27. reasons why you might want to fiddle with the keyboard buffer:
  28. - Call another program while exiting an already running program
  29. without tying up ANY memory or interfering with the running program
  30. in any way.
  31. - Change the keyboard buffer size to allow more or fewer keystrokes
  32. to be stored.
  33. - Write a TSR that can demonstrate other programs by simulating keystrokes,
  34.  without having or needing access to the other programs source code.
  35.  
  36. Things to consider:
  37. - EXTENSIVELY TEST ANY PROGRAM THAT STUFFS THE KEYBOARD BUFFER!!! Very slight
  38.   mistakes can create impressively buggy software! Make sure that the routines
  39.   do not leave any lasting effects (i.e. try running other programs after
  40.   running any program that stuffs the buffer). Assume that any software
  41.   that will stuff the keyboard will crash on your first effort writing it-
  42.   IN HEAVEN'S NAME SAVE TO FLOPPY DISK (THEN REMOVE THE DISK FROM YOUR DRIVE)
  43.   YOUR WORK IN PROGRESS BEFORE TRYING YOU NEW PROGRAM! HARD DISK USERS- DEBUG
  44.   AT YOUR OWN RISK! The memory area near the key board buffer is used for
  45.   important purposes by your computer. Accidentally writing to them will cause
  46.   the computer to operate unreliably- though not necessarily so unreliably
  47.   that you will notice it immediately! For example: while developing the
  48.   routines below, there was a bug present which would cause the procedure
  49.   to (apparently) not write to the buffer but it did not seem to cause any
  50.   other problems (TASM, TLINK, & Turbo C still worked fine). When I tried
  51.   starting Turbo Debugger, my computer would lock up! Once again: Test, Test,
  52.   Test!!!  
  53.  
  54. - These routines have only been tried on Heath/Zenith XT similar
  55.   computer (not 100% clone, but close). Verify on you own if the
  56.   concepts described below will work else where!
  57.  
  58. - If you are sure that your computers BIOS supports int 16h fun 05h you can
  59.   use it to safely write data to the keyboard buffer:
  60.   Calling Registers:    (From "System BIOS for IBM PC/XT/AT Computers &
  61.         ax=05h                  Compatibles", Phoenix Tech. Reference)
  62.         ch=scan code
  63.         cl=ascii character
  64.   Return Registers:
  65.         al= 00h=No Error, 01h= Buffer Full.
  66.   This BIOS int. is only supported on latter xt and on at computers. To
  67.   determine if the computer running a program supports INT 16h fun.'s 5h,10h,
  68.   12h...
  69.   (quoting Phoenix book...)
  70.   a) Use Fun. 05h to write FFFFh to the keyboard buffer. If AL returns 00h
  71.     then fun. 05h is supported.
  72.   b) Read the keyboard using fun. 10 as many times as there are words in
  73.     the keyboard buffer (the book recommends 15). If FFFFh is returned fun.
  74.     10h-12h are supported.
  75. - This program was NOT extensively tested. USE AT YOUR OWN RISK! Please
  76.   report any problems or useful information on keyboard stuffing to the
  77.   author so that I may keep these notes as complete as possible.
  78. - Note: IBM AT & PS/2 Keyboards generate different codes than do the XT
  79.   keyboards this program was written for. I don't believe that these
  80.   differences will affect this program in any way but this has not been
  81.   tested yet. You may wish to check that different keyboards work equally
  82.   well before using these routines in any important programs.
  83. - Note: This program was compiled (using Turbo Assembler & TLINK) with
  84.   case sensitivity & all debugging options on. Recompiling should not produce
  85.   any error messages.
  86. - IMPORTANT: Needless to say (but that won't stop me!)...
  87. ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
  88. +The information and routines below may be used without charge so long as    +
  89. +the author is not held, in any way, labial for the soundness of the routines+
  90. +or accuracy of the information. Any source code included in this file may   +
  91. +be considered "Public Domain".                              RLK Jan 9 1990  +
  92. ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
  93.  
  94.  
  95. +Notes on the Keyboard Buffer.
  96. ------------------------------
  97. The keyboard buffer is a circular buffer.
  98. The main components of the keyboard buffer are: 
  99. 1) A variable which keeps track of where the scan code for the oldest (first)
  100. unread key is located. This variable is often called the Head.
  101. 2) A variable which keeps track of where the scan code for the most recently 
  102. press key is located. This variable is often called the Tail.
  103. 3) A variable which contains the offset for the beginning of the keyboard
  104. buffer's memory area. This variable is often called the Start.
  105. 4) A variable which contains the offset for the end of the keyboard
  106. buffer's memory area. This variable is often called the End.
  107.  
  108. As keys are pressed, the scan code (WORD) is placed in a memory location
  109. pointed to by Tail. The tail pointer is then incremented by two (2 bytes=
  110. one word) unless the Tail pointer is 2 memory locations (bytes) before 
  111. the Head pointer in which case the keyboard buffer is now full.
  112. If incrementing the Tail pointer makes it greater than the value of End,
  113. Tail is set to equal Start.
  114. When a BIOS interrupt reads a scan code from the keyboard buffer, it reads
  115. the scan code pointed to by Head & then increments the Head pointer by
  116. two. (Note: No key is read from the buffer if the buffer is empty, i.e.
  117. if Head=Tail.)
  118. If incrementing the Head pointer makes it greater than the value of End,
  119. Head is set to equal Start.
  120.  
  121.  
  122. ==IBM========================================================================
  123.  (Heath/ZDS computer programmers, see next section).
  124. Note Worthy BIOS/RAM Locations concerning the Keyboard Buffer:
  125.  Note Segment = 040h
  126. Offset Data type       Description
  127. 80h    Word            Address of the start of the keyboard buffer, i.e.
  128.                        40h:[40h:80h] = the location of the first word of
  129.                        the keyboard buffer.
  130. 82h    Word            Address of the end of the keyboard buffer.
  131.  
  132. 1Eh-2Eh --------       16 bytes of the default keyboard buffer area.
  133.                        Note: By changing the start and end addresses
  134.                        of the keyboard buffer (while making sure that
  135.                        the RAM you point the buffer to isn't being/going
  136.                        to be used by anything else!) you can greatly
  137.                        increase/decrease the buffer size. (For example,the
  138.                        reference manual for my Heath Zenith 148 computer has
  139.                        a small program in it which changes the buffer to 4000 bytes.)
  140.  
  141. 1Ah    Word            Pointer to the first word to be read from the
  142.                        keyboard buffer- called "Head" by expert keyboard
  143.                        stuffers like you and I! Note: since the keyboard
  144.                        buffer is circular in nature, the first word of the
  145.                        keyboard buffer is not necessarily the first word
  146.